<%@ page import="org.grails.plugins.lookups.Lookup" %>
<%@ page import="org.ibiblio.terasaur.ui.UrlHelper" %>
<%
// UI option defaults
if (showCollection == null) {
    showCollection = true
}
if (showItemType == null) {
    showItemType = true
}

def urlHelper = new UrlHelper()
def item
def itemTypeValue
def collectionLink
def collectionName
def publishedDate
def ownerNickname

itemList.each {resultInstance->
    if (itemListType == 'solr') {
        item = resultInstance.document
        collectionId = item.collection_id
        collectionName = item.collection_name
        publishedDate = g.formatDate([date:item.published, type:'date', style:'LONG'])
        ownerNickname = item.owner_nickname
    } else {
        item = resultInstance
        collectionId = item.collection.id
        collectionName = item.collection.name
        publishedDate = joda.format([value:item.published, style:'L-'])
        ownerNickname = item.owner.username
    }

    if (showItemType && item.type) {
        itemTypeValue = Lookup.valueForCode("item.type", item.type)
    } else {
        itemTypeValue = null
    }
%>
                <li>
                    <strong><ts:itemLink item="${item}">${item.title}</ts:itemLink></strong>
                    <g:if test="${itemTypeValue}">(${itemTypeValue})</g:if>
                    <br/>
                    <span class="left"><ts:downloadInfo item="${resultInstance}"/></span>

<%
    if (showCollection) {
        if (itemListType == 'solr') {
            collectionLink = urlHelper.collectionLink(Long.parseLong(item.collection_id), item.collection_name, 'browse')
            collectionName = item.collection_name
        } else {
            collectionLink = urlHelper.collectionLink(item.collection, 'browse')
            collectionName = item.collection.name
        }
%>
                    <br/>
                    <span class="left">
                        <span class="alt-font">Collection</span> <span class="ndash alt-font">&ndash;</span> <a href="${collectionLink}">${collectionName}</a>
                    </span>
<%
    } // showCollection
%>
                    <span class="right">
                        <span class="by alt-font">Published by</span> ${ownerNickname}
                        <span class="date full-date"> <span class="ndash alt-font">&ndash;</span> ${publishedDate}</span><br/>
                    </span>
                    <span class="clear"></span>
                </li>
<%
} // itemList.each
%>
